package com.rabbitmq.consumer;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.exceptions.ClientException;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import util.SmsUtil;

import java.util.HashMap;
import java.util.Map;

@Component
@RabbitListener(queues = "zelin")
public class UserListener {

    @Autowired
    private SmsUtil smsUtil;


    @RabbitHandler
    public void register(Map map) throws ClientException {
        //得到验证码
        String code = (String) map.get("code");
        //得到手机号
        String mobile = map.get("mobile").toString();
        Map map1=new HashMap();
        map1.put("code",code);
        //组织验证码数据
        String param = JSON.toJSONString(map1);
        //向阿里大于发送短信
        smsUtil.sendSms(mobile,"SMS_176938629","我是大王",param);
    }
}
